#include "../mqserver/mq_message.hpp"
#include "../mqcommon/mq_helper.hpp"
#include <gtest/gtest.h>

wsmq::MessageManager::ptr mmp;

class MessageTest : public testing::Environment
{
public:
    virtual void SetUp() override
    {
        mmp = std::make_shared<wsmq::MessageManager>("./data/message");
        mmp->initQueueMessage("queue1");
    }
    virtual void TearDown() override
    {
        // mmp->clear();
    }
};

// TEST(message_test, insert_test) {
//     wsmq::BasicProperties properties;
//     properties.set_id(wsmq::UUIDHelper::uuid());
//     properties.set_delivery_mode(wsmq::DeliveryMode::DURABLE);
//     properties.set_routing_key("news.music.pop");
//     mmp->insert("queue1", &properties, "Hello World-1", true);
//     mmp->insert("queue1", nullptr, "Hello World-2", true);
//     mmp->insert("queue1", nullptr, "Hello World-3", true);
//     mmp->insert("queue1", nullptr, "Hello World-4", true);
//     mmp->insert("queue1", nullptr, "Hello World-5", false);
//     ASSERT_EQ(mmp->getable_count("queue1"), 5);
//     ASSERT_EQ(mmp->total_count("queue1"), 4);
//     ASSERT_EQ(mmp->durable_count("queue1"), 4);
//     ASSERT_EQ(mmp->waitack_count("queue1"), 0);
// }

TEST(message_test, delete_test) {
    ASSERT_EQ(mmp->getable_count("queue1"), 4);
    wsmq::MessagePtr msg1 = mmp->front("queue1");
    ASSERT_NE(msg1.get(), nullptr);
    ASSERT_EQ(msg1->payload().body(), std::string("Hello World-1"));
    ASSERT_EQ(mmp->getable_count("queue1"), 3);
    ASSERT_EQ(mmp->waitack_count("queue1"), 1);
    mmp->ack("queue1", msg1->payload().properties().id());
    ASSERT_EQ(mmp->waitack_count("queue1"), 0);
    ASSERT_EQ(mmp->durable_count("queue1"), 3);
    ASSERT_EQ(mmp->total_count("queue1"), 4);
}

int main(int argc, char* argv[])
{
    testing::InitGoogleTest(&argc, argv);
    testing::AddGlobalTestEnvironment(new MessageTest);
    return RUN_ALL_TESTS();
}